#输出也进行归一化
import numpy as np
import scipy.io as sio
from sklearn.preprocessing import MinMaxScaler
import os
from scipy import interpolate
from multiprocessing.dummy import Pool as ThreadPool

dataDir = './EMG_data/data/'
saveDir = './EMG_data/scaled/'

def findAllMat():
    """
    @description  :找到dataDir下所有的mat文件
    ---------
    @param  :
    -------
    @Returns  :
    -------
    """
    for root,dirs,files in os.walk(dataDir):
        for f in files:
            if(f.split('.')[-1]=="mat"):
                yield f
def data_scaler(input_list):
    """
    @description  :
    ---------
    @param  :
    -------
    @Returns  :
    -------
    """
    scaler = MinMaxScaler(copy=False)
    matData=input_list[0]
    matFile=input_list[1]
    norm_data={}
    norm_data['glove'] = []

    scaler.fit(matData['glove'])
    norm_data['glove']=scaler.transform(matData['glove'])
    matData['glove']=norm_data['glove']
    sio.savemat(saveDir+matFile, matData)

pool = ThreadPool()
mat_list=[]
for matFile in findAllMat(): 
    matData=sio.loadmat(dataDir+matFile)
    mat_list.append([matData,matFile])
results = pool.map(data_scaler, mat_list)
pool.close()
pool.join()